package com.medicine.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import pagination.Page;
import requestvo.AdminReqVo;
import requestvo.LabReqVo;

@Controller
public class LabController extends BaseController{
	Logger logger=Logger.getLogger(getClass().getName());
	@RequestMapping("/LabInfo")
	public void findsbkcxx(LabReqVo labReqVo,HttpServletResponse response) throws IOException{
		Page<LabReqVo> page=labService.findLabInfo(labReqVo);
		JSONObject jsonObject=new JSONObject();
		jsonObject.element("rows", page.getResults());
		jsonObject.element("total", page.getTotalRecord());
		response.setCharacterEncoding("UTF-8");  
		response.setContentType("application/json; charset=utf-8");  
		response.getWriter().print(jsonObject.toString());
		
	}
	@RequestMapping("/updateLab")
	public void updateLab(LabReqVo labReqVo,HttpServletResponse response) throws IOException{
		logger.info(labReqVo.toString());
		labService.updateLab(labReqVo);
		response.sendRedirect("Lab.html");
	}
	@RequestMapping("/addLab")
	public void addLab(LabReqVo labReqVo,HttpServletResponse response,HttpServletRequest request) throws IOException{	
		String gly_no=adminService.ifHasAdminName(labReqVo.getGly_name());
		if(gly_no!=null&&!gly_no.equals("")){
			labReqVo.setGly_no(gly_no);
			labService.addsbLab(labReqVo);
			response.sendRedirect("Lab.html");
		}else{
			response.setContentType("text/html;charset=UTF-8");
			PrintWriter out = response.getWriter();
			int code=-2;
			out.print(code);// 返回信息
		//	response.getWriter().print(code);
			out.flush();
			out.close();
		}
	}
	@RequestMapping("/delLab")
	public void delLab(String ids,HttpServletResponse response) throws IOException{
		String[] id=ids.split(",");
		String[] integers=new String[id.length];
		for(int i=0;i<id.length;++i)
			integers[i]=id[i];
		labService.delLab(integers);
		response.sendRedirect("Lab.html");
	}
	
 /*	@RequestMapping("/checksbno")
	public void checkYPBM(Integer yPBM,HttpServletResponse response) throws IOException{
		Ypkcxx ypxx= ypkcxxService.getYpkcxx(yPBM);
		if(ypxx==null)
			response.getWriter().print("null");
		else
			response.getWriter().print(ypxx.getyPMC());
	}*/
	/*
	@RequestMapping("/findAllYpxx")
	public void findAllYpxx(HttpServletResponse response) throws IOException{
		
		response.setCharacterEncoding("UTF-8");  
		response.setContentType("application/json; charset=utf-8"); 
		JsonObject jsonObject=new JsonObject();
		JSONArray jsonArray=JSONArray.fromObject(ypkcxxService.findAll());
		response.getWriter().print(jsonArray.toString());
	}
	*/
}
